//
//  CJClassLinesDetailViewController.m
//  KaiJing
//
//  Created by lanou on 16/1/26.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "CJClassLinesDetailViewController.h"
#import "CJCellBottomView.h"
#import <UIImageView+WebCache.h>

#define kXMargin 30

@interface CJClassLinesDetailViewController ()



/** 底部图片 */
@property (nonatomic, strong) UIImageView *baseImageView;

/** 正文Label */
@property (nonatomic, strong) UILabel *introLabel;

/** 影片名Label */
@property (nonatomic, strong) UILabel *subjectLabel;

/** 下方view */
@property (nonatomic, strong) CJCellBottomView *bottomView;

@end

@implementation CJClassLinesDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    self.view.backgroundColor = [UIColor blackColor];
    
    [self addAllSubViews];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [self.view addGestureRecognizer:tap];

}


- (void)tap {
    
    [self dismissViewControllerAnimated:NO completion:nil];
    
}

/**
 *  添加所有的子视图
 */
- (void)addAllSubViews {
    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, (kScreenHeight - kScreenWidth - 10) / 2, kScreenWidth, kScreenWidth + 10)];
    
    [self.view addSubview:view];
    
    
    // 添加底部ImageView
    _baseImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenWidth)];
    [view addSubview:_baseImageView];
    
    _introLabel = [[UILabel alloc] initWithFrame:CGRectMake(kXMargin, 0, kScreenWidth - kXMargin * 2, 200)];
    _introLabel.numberOfLines = 0;
    _introLabel.font = [UIFont systemFontOfSize:16];
    _introLabel.textColor = [UIColor whiteColor];
    [_baseImageView addSubview:_introLabel];
    
    _subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(kXMargin, 220, kScreenWidth - kXMargin * 2, 40)];
    _subjectLabel.textColor = [UIColor whiteColor];
    _subjectLabel.textAlignment = NSTextAlignmentRight;
    [_baseImageView addSubview:_subjectLabel];

    NSString *urlString = [NSString stringWithFormat:@"http://morguo.com/%@",_model.image];
    [_baseImageView sd_setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"recommend_selected"]];
    
    _introLabel.text = _model.intro;
    _subjectLabel.text = [NSString stringWithFormat:@"-- %@",_model.subject];
    
    // 自适应高度
    [self adjustViewsHeightWithContext:_model.intro];


}



/**
 *  自适应高度
 *
 *  @param context 传入的自适应高度文本
 */
- (void)adjustViewsHeightWithContext:(NSString *)context {
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil];
    CGRect rect = [context boundingRectWithSize:CGSizeMake(kScreenWidth - kXMargin * 2, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    CGFloat totalHeght = rect.size.height + 80;
    _introLabel.top = (kScreenWidth - totalHeght) / 2;
    _introLabel.height = rect.size.height;
    
    _subjectLabel.top = _introLabel.bottom + 40;
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
